package com.wenlin.myproduction.util;

import android.animation.AnimatorSet;
import android.animation.Keyframe;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;


import com.wenlin.myproduction.R;
import com.wenlin.myproduction.widget.RoundBlueProgressBar;

import static android.animation.ValueAnimator.INFINITE;

/**
 * @author 文琳
 * @time 2020/4/21 17:17
 * @desc 动画工具类
 */
public class AnimUtil {

    /**
     * 左右摇动+放大缩小的动画，引起用户注意
     *
     * @param view        控件
     * @param repeatTimes 重复次数
     */
    public static void tada(View view, int repeatTimes) {
        if (Checker.isNull(view)) return;
        float shakeFactor = 1.2f;
        //放大和缩小
        PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe(View.SCALE_X,
                Keyframe.ofFloat(0f, 1f),
                Keyframe.ofFloat(.1f, .9f),
                Keyframe.ofFloat(.2f, .9f),
                Keyframe.ofFloat(.3f, 1.1f),
                Keyframe.ofFloat(.4f, 1.1f),
                Keyframe.ofFloat(.5f, 1.1f),
                Keyframe.ofFloat(.6f, 1.1f),
                Keyframe.ofFloat(.7f, 1.1f),
                Keyframe.ofFloat(.8f, 1.1f),
                Keyframe.ofFloat(.9f, 1.1f),
                Keyframe.ofFloat(1f, 1f));
        PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe(View.SCALE_Y,
                Keyframe.ofFloat(0f, 1f),
                Keyframe.ofFloat(.1f, .9f),
                Keyframe.ofFloat(.2f, .9f),
                Keyframe.ofFloat(.3f, 1.1f),
                Keyframe.ofFloat(.4f, 1.1f),
                Keyframe.ofFloat(.5f, 1.1f),
                Keyframe.ofFloat(.6f, 1.1f),
                Keyframe.ofFloat(.7f, 1.1f),
                Keyframe.ofFloat(.8f, 1.1f),
                Keyframe.ofFloat(.9f, 1.1f),
                Keyframe.ofFloat(1f, 1f));
        //旋转
        PropertyValuesHolder pvhRotate = PropertyValuesHolder.ofKeyframe(View.ROTATION,
                Keyframe.ofFloat(0f, 0f),
                Keyframe.ofFloat(.1f, -3f * shakeFactor),
                Keyframe.ofFloat(.2f, -3f * shakeFactor),
                Keyframe.ofFloat(.3f, 3f * shakeFactor),
                Keyframe.ofFloat(.4f, -3f * shakeFactor),
                Keyframe.ofFloat(.5f, 3f * shakeFactor),
                Keyframe.ofFloat(.6f, -3f * shakeFactor),
                Keyframe.ofFloat(.7f, 3f * shakeFactor),
                Keyframe.ofFloat(.8f, -3f * shakeFactor),
                Keyframe.ofFloat(.9f, 3f * shakeFactor),
                Keyframe.ofFloat(1f, 0));
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(view, pvhScaleX, pvhScaleY, pvhRotate);
        animator.setDuration(1500);
        animator.setInterpolator(new AccelerateDecelerateInterpolator());
        animator.setRepeatMode(ValueAnimator.RESTART);
        animator.setRepeatCount(repeatTimes > 0 ? repeatTimes : INFINITE);
        animator.start();
    }

    /**
     * 左右摇动+放大缩小的动画，引起用户注意
     *
     * @param view 控件
     */
    public static void tada(View view) {
        tada(view, 0);
    }

    /**
     * 左右摇动+渐显的动画
     *
     * @param view        控件
     * @param shakeFactor 抖动程度
     */
    public static void rotate(View view, float shakeFactor) {
        // 旋转
        PropertyValuesHolder pvhRotate = PropertyValuesHolder.ofKeyframe(View.ROTATION,
                Keyframe.ofFloat(0f, 0f),
                Keyframe.ofFloat(.17f, 12f * shakeFactor),
                Keyframe.ofFloat(.25f, 12f * shakeFactor),
                Keyframe.ofFloat(.39f, -7f * shakeFactor),
                Keyframe.ofFloat(.45f, -7f * shakeFactor),
                Keyframe.ofFloat(.61f, 5f * shakeFactor),
                Keyframe.ofFloat(.65f, 5f * shakeFactor),
                Keyframe.ofFloat(.83f, -3.5f * shakeFactor),
                Keyframe.ofFloat(.85f, -3.5f * shakeFactor),
                Keyframe.ofFloat(1f, 0));
        //图的宽度是88*110
        view.setPivotX(52);
        view.setPivotY(9);
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(view, pvhRotate);
        animator.setDuration(3000);
        animator.start();
    }

    /**
     * 按钮选中动画
     *
     * @param view 控件
     */
    public static void btnOnAnim(View view) {
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator imgScaleUpYAnim = ObjectAnimator.ofFloat(view, "scaleY", 1f, 1.2f);
        imgScaleUpYAnim.setDuration(100);
        ObjectAnimator imgScaleUpXAnim = ObjectAnimator.ofFloat(view, "scaleX", 1f, 1.2f);
        imgScaleUpXAnim.setDuration(100);
//        AlphaAnimation alphaAnimation = new AlphaAnimation(0.9f, 1f);
//        alphaAnimation.setDuration(100);
//        alphaAnimation.setFillAfter(true);
        animatorSet.playTogether(imgScaleUpYAnim, imgScaleUpXAnim);
        animatorSet.start();
//        v.startAnimation(alphaAnimation);
    }

    /**
     * 按钮取消选中动画
     *
     * @param view 控件
     */
    public static void btnOffAnim(View view) {
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator imgScaleDownYAnim = ObjectAnimator.ofFloat(view, "scaleY", 1.2f, 1f);
        imgScaleDownYAnim.setDuration(100);
        ObjectAnimator imgScaleDownXAnim = ObjectAnimator.ofFloat(view, "scaleX", 1.2f, 1f);
        imgScaleDownXAnim.setDuration(100);
//        AlphaAnimation alphaAnimation2 = new AlphaAnimation(1f, 0.9f);
//        alphaAnimation2.setDuration(100);
//        alphaAnimation2.setFillAfter(true);
        animatorSet.playTogether(imgScaleDownXAnim, imgScaleDownYAnim);
        animatorSet.start();
//        v.startAnimation(alphaAnimation2);
    }

    /**
     * 返回左右抖动+放大缩小的动画
     *
     * @param view        控件
     * @param shakeFactor 抖动的程度
     * @return 所求
     */
    public static ObjectAnimator like(View view, float shakeFactor) {
        //放大和缩小
        PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe(View.SCALE_X,
                Keyframe.ofFloat(0f, 1f),
                Keyframe.ofFloat(.1f, 1.f),
                Keyframe.ofFloat(.2f, 1.05f),
                Keyframe.ofFloat(.3f, 1.1f),
                Keyframe.ofFloat(.4f, 1.15f),
                Keyframe.ofFloat(.5f, 1.2f),
                Keyframe.ofFloat(.6f, 1.15f),
                Keyframe.ofFloat(.7f, 1.1f),
                Keyframe.ofFloat(.8f, 1.05f),
                Keyframe.ofFloat(.9f, 1f),
                Keyframe.ofFloat(1f, 1f));
        PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe(View.SCALE_Y,
                Keyframe.ofFloat(0f, 1f),
                Keyframe.ofFloat(.1f, 1.f),
                Keyframe.ofFloat(.2f, 1.05f),
                Keyframe.ofFloat(.3f, 1.1f),
                Keyframe.ofFloat(.4f, 1.15f),
                Keyframe.ofFloat(.5f, 1.2f),
                Keyframe.ofFloat(.6f, 1.15f),
                Keyframe.ofFloat(.7f, 1.1f),
                Keyframe.ofFloat(.8f, 1.05f),
                Keyframe.ofFloat(.9f, 1f),
                Keyframe.ofFloat(1f, 1f));
        //旋转
        PropertyValuesHolder pvhRotate = PropertyValuesHolder.ofKeyframe(View.ROTATION,
                Keyframe.ofFloat(0f, 0f),
                Keyframe.ofFloat(.1f, -3f * shakeFactor),
                Keyframe.ofFloat(.2f, -3f * shakeFactor),
                Keyframe.ofFloat(.3f, 3f * shakeFactor),
                Keyframe.ofFloat(.4f, -3f * shakeFactor),
                Keyframe.ofFloat(.5f, 3f * shakeFactor),
                Keyframe.ofFloat(.6f, -3f * shakeFactor),
                Keyframe.ofFloat(.7f, 3f * shakeFactor),
                Keyframe.ofFloat(.8f, -3f * shakeFactor),
                Keyframe.ofFloat(.9f, 3f * shakeFactor),
                Keyframe.ofFloat(1f, 0));
        return ObjectAnimator.ofPropertyValuesHolder(view, pvhScaleX, pvhScaleY, pvhRotate).setDuration(1000);
    }

    /**
     * 执行顺时针旋转180度的动画
     *
     * @param view 控件
     */
    public static void clockwiseRotation(View view) {
        RotateAnimation ra = new RotateAnimation(0f, 180f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        ra.setDuration(300);
        ra.setFillAfter(true);
        view.startAnimation(ra);
    }

    /**
     * 执行顺时针旋转360度的动画
     *
     * @param view 控件
     */
    public static void gamePKMatchClockwiseRotation(View view) {
        if (Checker.isNull(view)) return;
        RotateAnimation ra = new RotateAnimation(0f, 360f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        ra.setDuration(5000);
        ra.setFillAfter(true);
        view.startAnimation(ra);
    }

    /**
     * 执行逆时针旋转180度的动画
     *
     * @param iv
     */
    public static void anticlockwiseRotation(View iv) {
        RotateAnimation ra = new RotateAnimation(180f, 0f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        ra.setDuration(300);
        ra.setFillAfter(true);
        iv.startAnimation(ra);
    }

    public static void alphaShow(View view) {
        if (Checker.isNull(view)) return;
        if (view.getVisibility() == View.VISIBLE) return;
        AlphaAnimation aa = new AlphaAnimation(0, 1f);
        aa.setDuration(300);
        aa.setFillAfter(false);
        view.startAnimation(aa);
        view.setVisibility(View.VISIBLE);
    }

    public static void alphaDismiss(View view) {
        if (Checker.isNull(view)) return;
        if (view.getVisibility() == View.GONE) return;
        AlphaAnimation aa = new AlphaAnimation(1f, 0);
        aa.setDuration(300);
        //这里设置为false，设为true，会导致视图不可见，但是还能触发点击事件
        aa.setFillAfter(false);
        view.startAnimation(aa);
        view.setVisibility(View.GONE);
    }

    public static void alphaInvisible(View view) {
        if (Checker.isNull(view)) return;
        if (view.getVisibility() == View.INVISIBLE) return;
        AlphaAnimation aa = new AlphaAnimation(1f, 0);
        aa.setDuration(300);
        //这里设置为false，设为true，会导致视图不可见，但是还能触发点击事件
        aa.setFillAfter(false);
        view.startAnimation(aa);
        view.setVisibility(View.INVISIBLE);
    }

    public static void fromBottom(Activity activity, View view) {
        if (Checker.isNull(view)) return;
        if (view.getVisibility() == View.VISIBLE) return;
        AnimationSet animationSet = new AnimationSet(true);
        Animation bottomIn = AnimationUtils.loadAnimation(activity, R.anim.up_in);
        bottomIn.setDuration(500);
        bottomIn.setInterpolator(new AccelerateDecelerateInterpolator());
        bottomIn.setFillAfter(true);
        Animation alphaIn = AnimationUtils.loadAnimation(activity, R.anim.alpha_in);
        alphaIn.setDuration(500);
        alphaIn.setInterpolator(new AccelerateDecelerateInterpolator());
        alphaIn.setFillAfter(true);
        animationSet.addAnimation(bottomIn);
        animationSet.addAnimation(alphaIn);
        view.setVisibility(View.VISIBLE);
        view.startAnimation(animationSet);
    }

    public static void fromBottom(Context context, View view) {
        if (Checker.isNull(view)) return;
        if (view.getVisibility() == View.VISIBLE) return;
        AnimationSet animationSet = new AnimationSet(true);
        Animation bottomIn = AnimationUtils.loadAnimation(context, R.anim.up_in);
        bottomIn.setDuration(500);
        bottomIn.setInterpolator(new AccelerateDecelerateInterpolator());
        bottomIn.setFillAfter(true);
        Animation alphaIn = AnimationUtils.loadAnimation(context, R.anim.alpha_in);
        alphaIn.setDuration(500);
        alphaIn.setInterpolator(new AccelerateDecelerateInterpolator());
        alphaIn.setFillAfter(true);
        animationSet.addAnimation(bottomIn);
        animationSet.addAnimation(alphaIn);
        view.setVisibility(View.VISIBLE);
        view.startAnimation(animationSet);
    }

    public static void moveToTop(Context context, View view) {
        if (Checker.isNull(view)) return;
        AnimationSet animationSet = new AnimationSet(true);
        Animation bottomIn = AnimationUtils.loadAnimation(context, R.anim.down_in);
        bottomIn.setDuration(500);
        bottomIn.setInterpolator(new AccelerateDecelerateInterpolator());
        bottomIn.setFillAfter(true);
        animationSet.addAnimation(bottomIn);
        view.startAnimation(animationSet);
    }

    public static void moveToBottom(Context context, View view) {
        if (Checker.isNull(view)) return;
        AnimationSet animationSet = new AnimationSet(true);
        Animation bottomOut = AnimationUtils.loadAnimation(context, R.anim.down_out);
        bottomOut.setDuration(500);
        bottomOut.setInterpolator(new AccelerateDecelerateInterpolator());
        bottomOut.setFillAfter(true);
        animationSet.addAnimation(bottomOut);
        view.startAnimation(animationSet);
    }

    public static void hideToBottom(Context context, View view) {
        if (Checker.isNull(view)) return;
        if (view.getVisibility() != View.VISIBLE) return;
        AnimationSet animationSet = new AnimationSet(true);
        Animation bottomOut = AnimationUtils.loadAnimation(context, R.anim.down_out);
        bottomOut.setDuration(500);
        bottomOut.setInterpolator(new AccelerateDecelerateInterpolator());
        bottomOut.setFillAfter(true);
        Animation alphaOut = AnimationUtils.loadAnimation(context, R.anim.alpha_out);
        alphaOut.setDuration(500);
        alphaOut.setInterpolator(new AccelerateDecelerateInterpolator());
        alphaOut.setFillAfter(true);
        animationSet.addAnimation(bottomOut);
        animationSet.addAnimation(alphaOut);
        view.setVisibility(View.GONE);
        view.startAnimation(animationSet);
    }

    public static void showFromTop(Activity activity, View view) {
        if (Checker.isNull(view)) return;
        if (view.getVisibility() == View.VISIBLE) return;
        AnimationSet animationSet = new AnimationSet(true);
        Animation topIn = AnimationUtils.loadAnimation(activity, R.anim.down_in);
        topIn.setDuration(500);
        topIn.setInterpolator(new AccelerateDecelerateInterpolator());
        topIn.setFillAfter(true);
        Animation alphaIn = AnimationUtils.loadAnimation(activity, R.anim.alpha_in);
        alphaIn.setDuration(500);
        alphaIn.setInterpolator(new AccelerateDecelerateInterpolator());
        alphaIn.setFillAfter(true);
        animationSet.addAnimation(topIn);
        animationSet.addAnimation(alphaIn);
        view.setVisibility(View.VISIBLE);
        view.startAnimation(animationSet);
    }

    public static void showFromTop(Context context, View view) {
        if (Checker.isNull(view)) return;
        if (view.getVisibility() == View.VISIBLE) return;
        AnimationSet animationSet = new AnimationSet(true);
        Animation bottomIn = AnimationUtils.loadAnimation(context, R.anim.down_in);
        bottomIn.setDuration(500);
        bottomIn.setInterpolator(new AccelerateDecelerateInterpolator());
        bottomIn.setFillAfter(true);
        Animation alphaIn = AnimationUtils.loadAnimation(context, R.anim.alpha_in);
        alphaIn.setDuration(500);
        alphaIn.setInterpolator(new AccelerateDecelerateInterpolator());
        alphaIn.setFillAfter(true);
        animationSet.addAnimation(bottomIn);
        animationSet.addAnimation(alphaIn);
        view.setVisibility(View.VISIBLE);
        view.startAnimation(animationSet);
    }

    public static void hideToTop(Context context, View view) {
        if (Checker.isNull(view)) return;
        if (view.getVisibility() != View.VISIBLE) return;
        AnimationSet animationSet = new AnimationSet(true);
        Animation bottomOut = AnimationUtils.loadAnimation(context, R.anim.up_out);
        bottomOut.setDuration(500);
        bottomOut.setInterpolator(new AccelerateDecelerateInterpolator());
        bottomOut.setFillAfter(true);
        Animation alphaOut = AnimationUtils.loadAnimation(context, R.anim.alpha_out);
        alphaOut.setDuration(500);
        alphaOut.setInterpolator(new AccelerateDecelerateInterpolator());
        alphaOut.setFillAfter(true);
        animationSet.addAnimation(bottomOut);
        animationSet.addAnimation(alphaOut);
        view.setVisibility(View.GONE);
        view.startAnimation(animationSet);
    }

    public static void transToLeft(View view) {
        TranslateAnimation transRight = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, -1f,
                Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 0f);
        transRight.setDuration(1200);
        transRight.setFillAfter(true);
        view.startAnimation(transRight);
    }

    /**
     * 两个小车一起动画
     *
     * @param left  左边的小车
     * @param right 右边的小车
     */
    public static void transToLeft(ImageView left, ImageView right, TextView tvProgress, RoundBlueProgressBar progressBar) {
        UI.setVisibility(tvProgress, View.INVISIBLE);
        UI.setVisibility(right, View.VISIBLE);
        TranslateAnimation transLeft = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, -1f,
                Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 0f);
        transLeft.setDuration(1200);
        transLeft.setFillAfter(false);
        TranslateAnimation transRight = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 1f,
                Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 0f);
        transRight.setDuration(1200);
        transRight.setFillAfter(true);
        //两车同步左移
        UI.startAnimation(left, transLeft);
        UI.startAnimation(right, transRight);
        transLeft.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                UI.setVisibility(right, View.INVISIBLE);
                UI.setImageResource(left, R.mipmap.farm_icon_car_empty);
                UI.setText(tvProgress, "再获得" + ValCommon.FULL_CAR_WITH_PLANTS + "个作物可获得一把铲子");
                UI.setProgress(progressBar, 0);
                UI.startShowAnimate(progressBar);
                UI.setVisibility(tvProgress, View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    public static void transToRight(View left, View right) {
        TranslateAnimation transLeft = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 1f,
                Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 0f);
        transLeft.setDuration(300);
        transLeft.setFillAfter(true);
        TranslateAnimation transRight = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, -1f,
                Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 0f);
        transRight.setDuration(300);
        transRight.setFillAfter(true);
        left.startAnimation(transLeft);
        right.startAnimation(transRight);
    }

    /**
     * 按钮上下浮动动画
     *
     * @param view 控件
     */
    public static void upDown(View view) {
        PropertyValuesHolder pv = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_Y,
                Keyframe.ofFloat(0f, 0f),
                Keyframe.ofFloat(1f, 6f));
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(view, pv);
        animator.setDuration(2000);
        animator.setInterpolator(new AccelerateDecelerateInterpolator());
        animator.setRepeatCount(INFINITE);
        animator.setRepeatMode(ValueAnimator.REVERSE);
        animator.start();
    }

    /**
     * 按钮左右浮动动画
     *
     * @param view 控件
     */
    public static void leftRight(View view) {
        PropertyValuesHolder pv = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_X,
                Keyframe.ofFloat(0f, 0f),
                Keyframe.ofFloat(1f, 50f));
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(view, pv);
        animator.setDuration(5000);
        animator.setInterpolator(new AccelerateDecelerateInterpolator());
        animator.setRepeatCount(INFINITE);
        animator.setRepeatMode(ValueAnimator.REVERSE);
        animator.start();
    }

    /**
     * 按钮左右浮动动画
     *
     * @param view 控件
     */
    public static void leftRightSmall(View view) {
        PropertyValuesHolder pv = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_X,
                Keyframe.ofFloat(0f, 0f),
                Keyframe.ofFloat(1f, 25f));
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(view, pv);
        animator.setDuration(4000);
        animator.setInterpolator(new AccelerateDecelerateInterpolator());
        animator.setRepeatCount(INFINITE);
        animator.setRepeatMode(ValueAnimator.REVERSE);
        animator.start();
    }

    /**
     * 水平翻转
     *
     * @param view      target
     * @param duration  time
     * @param direction 只能传1或-1，1为从左开始翻转，-1位从右开始翻转
     * @return 动画集合
     */
    public static AnimatorSet flip(View view, int duration, int direction) {
        AnimatorSet animSet = new AnimatorSet();
        if (Checker.notNull(view)) {
            if (direction != 1 && direction != -1) direction = 1;
            view.setCameraDistance(16000 * view.getResources().getDisplayMetrics().density);
            ObjectAnimator rotationY = new ObjectAnimator();
            rotationY.setDuration(duration).setPropertyName("rotationY");
            rotationY.setFloatValues(0, -90 * direction);
            ObjectAnimator _rotationY = new ObjectAnimator();
            _rotationY.setDuration(duration).setPropertyName("rotationY");
            _rotationY.setFloatValues(90 * direction, 0);
            _rotationY.setStartDelay(duration);
            ObjectAnimator scale = new ObjectAnimator();
            scale.setDuration(duration).setPropertyName("scaleY");
            scale.setFloatValues(1, 0.99f);
            ObjectAnimator _scale = new ObjectAnimator();
            _scale.setDuration(duration).setPropertyName("scaleY");
            _scale.setFloatValues(0.99f, 1);
            _scale.setStartDelay(duration);
            animSet.setTarget(view);
            rotationY.setTarget(view);
            _rotationY.setTarget(view);
            scale.setTarget(view);
            _scale.setTarget(view);
            animSet.playTogether(rotationY, _rotationY, scale, _scale);
            animSet.start();
        }
        return animSet;
    }
}
